package com.qiantu.phone.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import com.hjq.widget.layout.SettingBar;
import com.qiantu.phone.R;
import com.qiantu.phone.app.AppAdapter;
import com.qiantu.phone.app.AppApplication;
import com.qiantu.phone.bean.RecommendSceneDeviceBean;

public final class RecommendSceneActionAdapter extends AppAdapter<RecommendSceneDeviceBean> {

    public RecommendSceneActionAdapter(@NonNull Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {

        private final SettingBar itemDeviceAction;

        private ViewHolder() {
            super(R.layout.item_recommend_scene_action);
            itemDeviceAction = findViewById(R.id.item_device_action);
        }

        @Override
        public void onBindView(int position) {
            RecommendSceneDeviceBean item = getItem(position);
            itemDeviceAction.setLeftText(item.getName());
            int res = AppApplication.getInstance().getResourceId(item.getImage(), "attr");
            if(res != 0){
                itemDeviceAction.setLeftDrawable(AppApplication.getInstance().getThemeDrawable(res));
            }
            itemDeviceAction.setRightText(getString(R.string.selected_count_holder, item.getSelectedDeviceCount()));
        }
    }

    @Override
    public long getItemId(int position) {
        return getData().get(position).hashCode();
    }
}